package cn.iocoder.yudao.module.handguard.service.userbasetable5;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable5.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable5.UserBaseTable5DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable5.UserBaseTable5Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable5.UserBaseTable5Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 公积金贷 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable5ServiceImpl implements UserBaseTable5Service {

    @Resource
    private UserBaseTable5Mapper userBaseTable5Mapper;

    @Override
    public Long createUserBaseTable5(UserBaseTable5CreateReqVO createReqVO) {
        // 插入
        UserBaseTable5DO userBaseTable5 = UserBaseTable5Convert.INSTANCE.convert(createReqVO);
        userBaseTable5Mapper.insert(userBaseTable5);
        // 返回
        return userBaseTable5.getId();
    }

    @Override
    public void updateUserBaseTable5(UserBaseTable5UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable5Exists(updateReqVO.getId());
        // 更新
        UserBaseTable5DO updateObj = UserBaseTable5Convert.INSTANCE.convert(updateReqVO);
        userBaseTable5Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable5(Long id) {
        // 校验存在
        validateUserBaseTable5Exists(id);
        // 删除
        userBaseTable5Mapper.deleteById(id);
    }

    private void validateUserBaseTable5Exists(Long id) {
        if (userBaseTable5Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE5_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable5DO getUserBaseTable5(Long id) {
        LambdaQueryWrapper<UserBaseTable5DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable5DO::getApplicationId,id);
        return userBaseTable5Mapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserBaseTable5DO> getUserBaseTable5List(Collection<Long> ids) {
        return userBaseTable5Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<UserBaseTable5DO> getUserBaseTable5Page(UserBaseTable5PageReqVO pageReqVO) {
        return userBaseTable5Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable5DO> getUserBaseTable5List(UserBaseTable5ExportReqVO exportReqVO) {
        return userBaseTable5Mapper.selectList(exportReqVO);
    }

}
